<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			// 资源的加载
			
			function loadImg(){
				return new Promise((res,rej)=>{
						// let src = "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F4k%2Fs%2F02%2F2109242332225H9-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1642643996&t=9f9b70fd8391a0eee084e3e436b1ab3f";
						let src = "https://gimg2.baidu";
						let img = new Image();
						img.src = src;
						img.onload = function(){
							// 加载成功
							// 把图片添加到dom里；
							// document.body.appendChild(img);
							res(this);
						}
						img.onerror = function(){
							// console.log("加载失败");
							rej("加载失败111");
						}
				})
				
			}
			
			// catch 可以把整个then链上的错误捕捉到 然后输出；
			loadImg().then(res=>{
				document.body.appendChild(res);
			}).catch(err=>{
				console.log(err);
			})
			
			
			
			
		</script>
	</body>
</html>
